package com.iraeta.controller.system;

import com.alibaba.fastjson.JSONObject;
import com.iraeta.controller.BaseController;
import com.iraeta.entity.CustomOrg;
import com.iraeta.entity.TreeNode;
import com.iraeta.service.sys.ISysOrgService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController(value = "OrgController")
@RequestMapping("sys/org")
public class OrgController extends BaseController {
    @Resource
    ISysOrgService iSysOrgService;

    @RequestMapping("orgtreedata")
    public String orgTreeData(@RequestBody JSONObject jo){
        Integer orgId =  jo.getInteger("orgId") == null ? CustomOrg.root : jo.getInteger("orgId");
        List<TreeNode> roleList = iSysOrgService.listChildrenOrg(orgId);
        return this.success(roleList);
    }

    @RequestMapping("orgtongbu")
    public String orgTongBu(){
        iSysOrgService.tongBuOrg();
        iSysOrgService.tongBuUser();
        return this.success();
    }
}
